<?php
/**
 * Created by PhpStorm.
 * User: 李振磊
 * Date: 2019/3/10
 * Time: 12:07
 */
function p($data)
{
    echo "<pre>";
    print_r($data);
    echo "</pre>";
}

function v($data)
{
    echo "<pre>";
    var_dump($data);
    echo "</pre>";
}

//p(array_change_key_case(['abc' => '123', 'def' => '456', 4 => 3], CASE_UPPER));
//
////var_dump(array_change_key_case(1,CASE_UPPER));
//p(array_chunk(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5], 2, true));
//
//$records = array(
//    array(
//        'id' => 2135,
//        'first_name' => 'John',
//        'last_name' => 'Doe',
//    ),
//    array(
//        'id' => 3245,
//        'first_name' => 'Sally',
//        'last_name' => 'Smith',
//    ),
//    array(
//        'id' => 5342,
//        'first_name' => 'Jane',
//        'last_name' => 'Jones',
//    ),
//    array(
//        'id' => 5623,
//        'first_name' => 'Peter',
//        'last_name' => 'Doe',
//    )
//);
//$data = array_column($records, 'first_name', 'id');
//p($data);
//
//$keys = array(1 => "a", '22' => 'b', "c");
//$values = array(1, 2, "c" => 3);
//$data = array_combine($keys, $values);
//p($data);
//
//$arrays = array("1", "hello", "world", 1);
//$result = array_count_values($arrays);
//p($result);
//
//$array1 = array("a" => "green", "b" => "brown", "c" => "bule", "red","bule");
//$array2 = array("a" => "green", 1 => "red");
//$result = array_diff_assoc($array1, $array2);
//p($result);
//
//$result = array_diff_key($array1, $array2);
//p($result);
//
//$array1 = array("a"=>"green","red","blue","red");
//$array2 = array("b"=>"green","yellow","red");
//$result = array_diff($array1,$array2);
//p($result);

//function key_compare_func($a, $b)
//{
//    if ($a === $b) {
//        return 0;
//    }
//    return ($a > $b) ? 1 : -1;
//
//}
//
//$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
//$array2 = array("a" => "green", "yellow", "red");
//$result = array_diff_uassoc($array1, $array2, 'key_compare_func');
//p($result);



//$keys = array('foo',5,10,'bar');
//$a = array_fill_keys($keys,"banana");
//p($a);
//
//$a = array_fill(1,6,"banana");
//p($a);
//
//$b = array_fill(-2,6,'banana');
//p($b);

//$entry = array(
//    0 => "foo",
//    1 => false,
//    2 => -1,
//    3 => null,
//    4 => ''
//);
//p(array_filter($entry));

//function odd($var)
//{
//    return($var&1);
//}
//
//function even($var)
//{
//    return (!($var&1));
//}
//
//$array1 = array("a"=>1,"b"=>2,"c"=>3);
//$array2 = array(6,7,8,9,10);
//
//p(array_filter($array1,"odd"));
//p(array_filter($array2,"even"));

//$input = array("oranges","apples","pears");
//$flipped = array_flip($input);
//p($flipped);

//$array1 = array("a"=>"apple","b"=>"banana","c"=>"ccbb");
//$array2 = array("a1"=>"apple1","b1"=>"banana","d"=>"ccbb");
//
//p(array_intersect($array1,$array2));
//
//$array1 = array("a"=>"apple","b"=>"banana","c"=>"ccbb");
//$array2 = array("a"=>"apple1","b1"=>"banana","d"=>"ccbb");
//p(array_intersect_key($array1,$array2));
//
//$array1 = array("a"=>"apple","b"=>"banana","c"=>"ccbb");
//$array2 = array("a"=>"apple","b1"=>"banana","d"=>"ccbb");
//p(array_intersect_assoc($array1,$array2));

//$search_array = array('first'=>1,'second'=>2,'red');
//v(array_key_exists('1',$search_array));
//v(array_key_exists('first',$search_array));
//v(array_key_exists(0,$search_array));

//$search_array = array('first'=>null,'second'=>2);
//v(isset($search_array['first']));
//v(array_key_exists('first',$search_array));

$array = ['a' => 1, 'b' => 2, 'c' => 3];
$firstKey = array_key_first($array);
var_dump($firstKey);

